﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace XqWebSite
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void But_login_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.ToString().Trim() == "" || TextBox2.Text.ToString().Trim() == "")
            {
                Response.Write("<script>javascript:alert('请输入完整');history.back();</script>");
                Response.End();
            }

            if (this.DropDownList1.SelectedIndex==0)
            {
                string SQL = "select * from Admin where username='" + this.TextBox1.Text + "' and password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "管理员";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Response.Redirect("AdIndex2.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }

            }
            else if(this.DropDownList1.SelectedIndex==1){
                string SQL = "select * from XiaoQuZhuHu where UserName='" + this.TextBox1.Text + "' and Password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "住户";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Session["XM"] = dt.Rows[0]["username"].ToString();
                    Response.Redirect("ZhIndex2.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }
               
            }else if(this.DropDownList1.SelectedIndex==2){
                string SQL = "select * from BaoAn where UserName='" + this.TextBox1.Text + "' and Password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "保安";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Session["XM"] = dt.Rows[0]["username"].ToString();
                    Response.Redirect("AbIndex2.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }


           
            }
            else if (this.DropDownList1.SelectedIndex ==3)
            {
                string SQL = "select * from WeiXiuRenYuan where UserName='" + this.TextBox1.Text + "' and Password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "维修人员";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Session["XM"] = dt.Rows[0]["username"].ToString();
                    Response.Redirect("WxIndex2.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }

                 Response.Redirect("WxIndex2.aspx");
            }

        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}